Hey Spiceheads, good morning to all!

I am trying to generate a list of mailboxes by last logon time in order to clean up Exchange a bit by running the following:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Windows\system32> Get-Mailbox -Resultsize Unlimited | Get-MailboxStatistics | Sort LastLogonTime | select Displayn
ame, lastlogontime
The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
 spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
+ Get-Mailbox <<<<  -Resultsize Unlimited | Get-MailboxStatistics | Sort LastLogonTime | select Displayname, lastlogont
ime
    + CategoryInfo          : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Windows\system32>

As you can see by the results, the term Get-Mailbox is not being recognized. What am I missing here? Any alternative scripts to run?

2 Spice ups

Are you running Powershell 4 (which autoimports) or have you imported the module for Exchange?
Are you running the command on the server or your workstation?
Are you running it straight through Powershell or using EMS?

Make sure you have an actual Exchange Powershell session open.

For Exchange 2013 the shortcut to open this on the server itself should look something like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "

Alternatively you can connect to a remote session from any PC that has a recent powershell install by following these steps (only works with Exchange 2010 and newer):

1 Spice up

Are you running Powershell 4 (which autoimports) or have you imported the module for Exchange? Not sure.

Are you running the command on the server or your workstation? From my workstation via RDP

Are you running it straight through Powershell or using EMS? Straight through PS, this is a 2010 Exchange server.

Looks like connecting remotely via PS is working.

Ah this will be why, in a standard Powershell session the Exchange cmdlets do not get loaded.

You either need to use the Exchange Powershell Session shortcut that Exchange should installed, import the the Exchange PS module into your session or start a remote PS session.

My preferred route is often to use a full remote PS session as this has the benefit of only loading the cmdlets that your user account has access to so you don’t get confused wondering why a cmd is erroring (this works really well where you delegate access to someone).

1 Spice up

Thanks, as always, I learn more and more everyday on SW!